package 单词接龙;

import java.util.Scanner;

public class Main {
    static int N = 30, n, ans;
    static int[] used = new int[N];
    static int[][] st = new int[N][N];
    static String[] words = new String[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        for (int i = 0; i < n; i++) {
            words[i] = in.next();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                String a = words[i];
                String b = words[j];
                for (int k = 1; k < Math.min(a.length(), b.length()); k++) {
                    if (a.substring(a.length() - k).equals(b.substring(0, k))) {
                        st[i][j] = k;
                        break;
                    }
                }
            }
        }
        char lead = in.next().charAt(0);
        for (int i = 0; i < n; i++) {
            if (lead == words[i].charAt(0)) {
                dfs(words[i], i);
            }
        }
        System.out.println(ans);
    }

    private static void dfs(String s, int last) {
        ans = Math.max(ans, s.length());
        used[last]++;
        for (int i = 0; i < n; i++) {
            if (st[last][i] > 0 && used[i] < 2) {
                dfs(s + words[i].substring(st[last][i]), i);
            }
        }
        used[last]--;
    }
}
